package interfaces.console;

import settings.CheatConfig;
import settings.CommonSettings;
import settings.Config;
import settings.ControlSettings;
import settings.GraphicSettings;

import gameStates.absGamesStates.gui.AbsConsoleState;
import interfaces.console.commands.ChangeProfileCommand;
import interfaces.console.commands.CommonChangeCommand;
import interfaces.console.commands.ControlsChangeCommand;
import interfaces.console.commands.GraphicChangeCommand;
import interfaces.console.commands.QuickHunterCommand;
import interfaces.console.commands.QuitCommand;
import interfaces.console.commands.SettingsCommand;
import interfaces.superWidgets.InterfaceElement;

public class ConsoleElement extends InterfaceElement {
	
	private Console console;
	
	public ConsoleElement(AbsConsoleState consoleState) {
		super(consoleState);
		
		int halfHeight = getHeight() / 2;
		
		console = new Console(getWidth(), halfHeight);
		console.setXY(0, halfHeight);
		addWidget(console);
		
		console.addCommand(new QuitCommand());
		console.addCommand(new ChangeProfileCommand());
		console.addCommand(new QuickHunterCommand());
		
		for(String key : GraphicSettings.get().getKeys()) {
			console.addCommand(new GraphicChangeCommand(key, GraphicSettings.get()));
		}
		
		for(String key : ControlSettings.get().getKeys()) {
			console.addCommand(new ControlsChangeCommand(key, ControlSettings.get()));
		}
		
		for(String key : CommonSettings.get().getKeys()) {
			console.addCommand(new CommonChangeCommand(key, CommonSettings.get()));
		}
		
		for(String key : Config.get().getKeys()) {
			console.addCommand(new SettingsCommand(key, Config.get()));
		}
		
		for(String key : CheatConfig.get().getKeys()) {
			console.addCommand(new SettingsCommand(key, CheatConfig.get()));
		}
	}
	
	@Override
	public void updateMoney(int newMoney) {}
	
	public void setFocus() {
		guiState.getGUIDisplay().setFocusedWidget(console);
	}
	
	public void updateConsoleAlignment() {
		int halfHeight = getHeight() / 2;
		console.setSize(getWidth(), halfHeight);
		console.setXY(0, halfHeight);
	}
}